<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzb.erp.api.pc.material.mapper.MaterialRecordMapper">

    <select id="getList" resultType="com.hzb.erp.api.pc.material.pojo.MaterialRecordVO">
        select t1.*, t2.name staff_name,
        t3.name as student_name, t4.name as material_name
        from material_record t1
        left join material t4 on t4.id = t1.material_id
        left join staff t2 on t2.id = t1.staff_id
        left join student t3 on t3.id = t1.student_id
        <where>
            <if test="param.materialId != null">
                AND t1.material_id = #{param.materialId}
            </if>
            <if test="param.studentId != null">
                AND t1.student_id = #{param.studentId}
            </if>
            <if test="param.staffId != null">
                AND t1.staff_id = #{param.staffId}
            </if>
            <if test="param.changeType != null">
                AND t1.change_type = #{param.changeType}
            </if>
            <if test="param.startDate != null and param.endDate != null">
                AND ( date(t1.add_time) &gt;= #{param.startDate} and  date(t1.add_time) &lt;= #{param.endDate} )
            </if>
        </where>
        order by t1.id desc
    </select>

</mapper>
